package me.jiatao.baselibrary.rx


import io.reactivex.Observer
import io.reactivex.disposables.Disposable
import me.jiatao.baselibrary.exception.BaseException
import me.jiatao.baselibrary.mvp.view.BaseView


/**
 * Rx订阅者默认实现
 */
abstract class BaseSubscriber<T>(private val baseView: BaseView) : Observer<T> {
    override fun onSubscribe(d: Disposable) {}

    abstract override fun onNext(data: T)

    override fun onError(e: Throwable) {
        baseView.hideLoading()
        if (e is BaseException) {
            baseView.onError(e.msg)
        }
    }

    override fun onComplete() {
        baseView.hideLoading()
    }


}
